
var recharge_list;

//每页显示条数
var page_count = 15;

getRechargeList();

/**
 * 获取用户充值列表
 */
function getRechargeList() {

    var userId = baseFn.getQueryString('userId')

    if (userId == null || userId.length == 0){
        return;
    }

    $.ajax({
        url: baseUrl.base + 'sales/userDetail',
        type: 'post',
        data: {'userId': userId},
        success: function (data) {

            if (data.code == 0) {

                var res = data.results;

                recharge_list = res;

                cutPagination(1);

                // 配置分页
                $("#p1").pagination({
                    totalData: recharge_list.length,
                    showData:page_count,
                    callback: function (idx) {
                        cutPagination(idx);
                    }
                });
            }
        }
    })
}

/**
 * 分页
 * @param page 从1开始
 */
function cutPagination(page) {

    var start = (page - 1) * page_count;
    var end = start + page_count;

    if (end > recharge_list.length) {
        end = recharge_list.length;
    }

    $("#tbody").empty();
    for (var i = start; i < end; i++) {
        var recharge = recharge_list[i];

        var rechageTime = recharge.rechageTime;
        var rechageMoney = recharge.rechageMoney;
        var backRate = recharge.backRate;
        var backMoney = recharge.backMoney;

        var tr = document.createElement("tr");
        var td = document.createElement("td");
        var text = document.createTextNode(i + 1 + "");
        td.appendChild(text);
        tr.appendChild(td);

        var td = document.createElement("td");
        var text = document.createTextNode(timestampToTime(rechageTime));
        td.appendChild(text);
        tr.appendChild(td);

        var td = document.createElement("td");
        var text = document.createTextNode(rechageMoney + "KSH");
        td.appendChild(text);
        tr.appendChild(td);

        var td = document.createElement("td");
        var text = document.createTextNode(backRate);
        td.appendChild(text);
        tr.appendChild(td);

        var td = document.createElement("td");
        var text = document.createTextNode(backMoney + "KSH");
        td.appendChild(text);
        tr.appendChild(td);

        document.getElementById("tbody").append(tr);
    }
}